<?php
function themeConfig($form) {

    echo '<link rel="stylesheet" href="' . Helper::options()->themeUrl . '/assets/css/option.css"/>';
    echo '<script src="' . Helper::options()->themeUrl . '/assets/js/jquery.min.js"></script>';
    echo '<script src="' . Helper::options()->themeUrl . '/assets/js/option.js"></script>';
?><style>
.typecho-option-submit {
    display: block!important;
}
</style><div class="cat_option_menu"><ul class="menulist"><li class="menu" id="cat_notice">欢迎使用</li><li class="menu" id="cat_basic">基本设置</li></ul></div><?php
$str1 = explode('/themes/', Helper::options()->themeUrl);
$str2 = explode('/', $str1[1]);
$name=$str2[0];
$db = Typecho_Db::get();
$sjdq=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:'.$name));
$ysj = isset($sjdq['value'])?$sjdq['value']:'';
if(isset($_POST['type'])) {
	if($_POST["type"]=="备份模板设置数据") {
		if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:'.$name.'bf'))) {
			$update = $db->update('table.options')->rows(array('value'=>$ysj))->where('name = ?', 'theme:'.$name.'bf');
			$updateRows= $db->query($update);
			echo '<div class="typecho-option" style="display: block;"><div style="font-size:20px;color:green;" class="tongzhi home">备份已更新，请等待自动刷新！如果等不到请点击';
			?><a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div></div><script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2500);
			</script><?php
		} else {
			if($ysj) {
				$insert = $db->insert('table.options')
				    ->rows(array('name' => 'theme:'.$name.'bf','user' => '0','value' => $ysj));
				$insertId = $db->query($insert);
				echo '<div class="typecho-option" style="display: block;"><div style="font-size:20px;color:green;" class="tongzhi home">备份完成，请等待自动刷新！如果等不到请点击';
				?><a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div></div><script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2500);
				</script><?php
			}
		}
	}
	if($_POST["type"]=="还原模板设置数据") {
		if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:'.$name.'bf'))) {
			$sjdub=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:'.$name.'bf'));
			$bsj = $sjdub['value'];
			$update = $db->update('table.options')->rows(array('value'=>$bsj))->where('name = ?', 'theme:'.$name);
			$updateRows= $db->query($update);
			echo '<div class="typecho-option" style="display: block;"><div style="font-size:20px;" class="tongzhi home">检测到模板备份数据，恢复完成，请等待自动刷新！如果等不到请点击';
			?><a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div></div><script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2000);
			</script><?php
		} else {
			echo '<div class="typecho-option" style="display: block;"><div style="font-size:20px;color:red;" class="tongzhi home">没有模板备份数据，恢复不了哦！</div></div>';
		}
	}
	if($_POST["type"]=="删除备份数据") {
		if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:'.$name.'bf'))) {
			$delete = $db->delete('table.options')->where ('name = ?', 'theme:'.$name.'bf');
			$deletedRows = $db->query($delete);
			echo '<div class="typecho-option" style="display: block;"><div style="font-size:20px;color:green;" class="tongzhi home">删除成功，请等待自动刷新，如果等不到请点击';
			?><a href="<?php Helper::options()->adminUrl('options-theme.php'); ?>">这里</a></div></div><script language="JavaScript">window.setTimeout("location=\'<?php Helper::options()->adminUrl('options-theme.php'); ?>\'", 2500);
			</script><?php
		} else {
			echo '<div class="typecho-option" style="display: block;"><div style="font-size:20px;color:orange;" class="tongzhi home">不用删了！备份不存在！！！</div></div>';
		}
	}
}
function get_between($input, $start, $end)
{
    $substr = substr($input, strlen($start) + strpos($input, $start), (strlen($input) - strpos($input, $end)) * (-1));
    return $substr;
}
$contents = get_between($contents,'<ol class="comment-list">','</ol>');
$contents_arr = explode("</li>",$contents);
echo '<div class="typecho-option cat_notice" style="display: block;">';
echo '<label class="typecho-label">首次使用</label>';
echo '<div class="description">
        博主昵称，请在<span style="color:cornflowerblue;"> 控制台-个人设置-昵称 </span>里修改<br>
        站点名称与站点描述，请在<span style="color:cornflowerblue;"> 设置-基本 </span>里修改<br></div>';
echo '</div>';
echo '<div class="typecho-option cat_notice" style="display: block;"><label class="typecho-label">备份选项</label><form class="protected home" action="?'.$name.'bf" method="post"><input type="submit" name="type" class="backup_botton backup_botton_green" value="备份模板设置数据" /><input type="submit" name="type" class="backup_botton backup_botton_green" value="还原模板设置数据" /><input type="submit" name="type" class="backup_botton backup_botton_red" value="删除备份数据" /></form></div>';
echo '<div class="typecho-option cat_notice" style="text-align:center;display: block;"><div class="typecho-label"><span style="color:#ff6a6a;">👑👑👑<span><span style="color:#E56600;"><b><a href="https://LIYIZI.TOP/" target="_blank">ZWingYan</a> Copyright ©</b></span></div></div>';
    $ZWingYan_favicon = new Typecho_Widget_Helper_Form_Element_Text(
        'ZWingYan_favicon',
        null,
        null,
        '设置网站favicon',
        '介绍：输入favicon地址，使用ico格式'
    );
    $ZWingYan_favicon->setAttribute('class', 'typecho-option cat_basic');
    $form->addInput($ZWingYan_favicon);
    
    // 👑👑👑👑👑👑👑👑👑👑
    
    $ZWingYan_birthday = new Typecho_Widget_Helper_Form_Element_Text(
        'ZWingYan_birthday',
        NULL,
        NULL,
        '网站成立日期',
        '介绍：用于显示当前站点已经运行了多少时间。<br>
         注意：填写时务必保证填写正确！例如：2022/6/22 00:00:00 <br>
         其他：不填写则不显示'
    );
    $ZWingYan_birthday->setAttribute('class', 'typecho-option cat_basic');
    $form->addInput($ZWingYan_birthday);
    
    // 👑👑👑👑👑👑👑👑👑👑
    
    $ZWingYan_Index_user_avatar = new Typecho_Widget_Helper_Form_Element_Text(
        'ZWingYan_Index_user_avatar',
        NULL,
        NULL,
        '导航自定义头像',
        '介绍：导航自定义头像地址'
    );
    $ZWingYan_Index_user_avatar->setAttribute('class', 'typecho-option cat_basic');
    $form->addInput($ZWingYan_Index_user_avatar);
        
    // 👑👑👑👑👑👑👑👑👑👑
    
    $ZWingYan_wz = new Typecho_Widget_Helper_Form_Element_Text(
        'ZWingYan_wz',
        NULL,
        NULL,
        '所在位置',
        '介绍：默认福建'
    );
    $ZWingYan_wz->setAttribute('class', 'typecho-option cat_basic');
    $form->addInput($ZWingYan_wz);
        
    // 👑👑👑👑👑👑👑👑👑👑
    
    $ZWingYan_IndexBackgroundImage = new Typecho_Widget_Helper_Form_Element_Text(
        'ZWingYan_IndexBackgroundImage',
        NULL,
        NULL,
        '首页侧边显示——图片背景',
        '介绍：请输入需要显示的背景图<br>
         说明：若想多图显示可使用api图片地址'
    );
    $ZWingYan_IndexBackgroundImage->setAttribute('class', 'typecho-option cat_basic');
    $form->addInput($ZWingYan_IndexBackgroundImage);
    
    // 👑👑👑👑👑👑👑👑👑👑
    
    $ZWingYan_dose = new Typecho_Widget_Helper_Form_Element_Text(
        'ZWingYan_dose',
        NULL,
        NULL,
        '首页说明',
        '说明：感觉自己读书就是在浪费钱，所以既然不能读万卷书那就行万里路了。'
    );
    $ZWingYan_dose->setAttribute('class', 'typecho-option cat_basic');
    $form->addInput($ZWingYan_dose);
    
    // 👑👑👑👑👑👑👑👑👑👑
    
    $ZWingYan_icp = new Typecho_Widget_Helper_Form_Element_Text(
        'ZWingYan_icp',
        NULL,
        NULL,
        'ICP网备',
        '介绍：页面底部显示工信部备案号<br>
         示例：京ICP证030173号'
    );
    $ZWingYan_icp->setAttribute('class', 'typecho-option cat_basic');
    $form->addInput($ZWingYan_icp);
    
    // 👑👑👑👑👑👑👑👑👑👑
    
    $ZWingYan_gwab = new Typecho_Widget_Helper_Form_Element_Text(
        'ZWingYan_gwab',
        NULL,
        NULL,
        '公网安备',
        '介绍：页面底部显示公网安备备案号<br>
         示例：京公网安备11000002000001号'
    );
    $ZWingYan_gwab->setAttribute('class', 'typecho-option cat_basic');
    $form->addInput($ZWingYan_gwab);
    
}